const { imgUrl } = getApp().globalData;
import { mineApi } from "../../../utils/request/api/mine";
Component({
  behaviors: [],
  properties: {},
  data: {
    imgUrl: imgUrl + "tender/",
    isEmpty: false,
    refresherStatus: false,
    list: [],
    ways: ['标题', '全文', '精准']
  },
  lifetimes: {
    created() {
    },
    attached() {
      console.log("attached attached")
      this.getList()
    },
    moved() {},
    detached() {},
  },
  methods: {
    toCreate() {
      wx.navigateTo({
        url: "/pages/tender/subscribe/addsub/addsub?type=add",
      });
    },
    toSubDetail() {
      wx.navigateTo({
        url: "/pages/tender/subscribe/subinfo/subinfo",
      });
    },
    toSubDetail2(event) {
      const that = this;
      const index = event.currentTarget.dataset.index;
      wx.navigateTo({
        url: "/pages/tender/subscribe/addsub/addsub?type=edit",
        success: function (res) {
          const eventChannel = res.eventChannel;
          eventChannel.emit("sub_info", { data: that.data.list[index] });
        },
      });
    },
    deleteSub(event) {
      const index = event.currentTarget.dataset.index;
      mineApi.deleteSubscription({
        id: this.data.list[index].id
      }).then((res) => {
        console.log("res res === ", res);
        this.getList()
      });
    },
    // 下拉刷新
    handleRefresherRefresh() {
      this.setData({
        refresherStatus: true,
      });
      this.getList();
    },
    getList() {
      mineApi.getSubscriptionList().then((res) => {
        console.log("res res === ", res);
        this.setData({
          list: res.data,
          refresherStatus: false,
        });
      });
    },
  },
});
